package com.fastgeek.platform.db.datasource.config;

import com.fastgeek.platform.db.datasource.*;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.jdom.Element;

public class DBXmlParser extends IXmlParser {
	@Override
	public void parse(Element root, Map results) throws Exception {
		List<Element> dataBases = (List<Element>) root.getChildren();
		for (Element dbEle : dataBases) {
			if (!"database".equals(dbEle.getName()))
				continue;

			String dbName = dbEle.getAttributeValue("name");
			boolean isDefault = dbEle.getAttributeValue("default") != null
					&& "true".equals(dbEle.getAttributeValue("default"));
			String userName = dbEle.getChildText("username");
			String userPwd = dbEle.getChildText("password");
			String url = dbEle.getChildText("url");
			String driverName = dbEle.getChildText("driver").trim();

			Properties extendConfig = new Properties();
			extendConfig
					.setProperty("max-idle-time", dbEle.getChildText("url"));

			results.put(dbName, new DBConfig(driverName, url, userName,
					userPwd, isDefault, extendConfig));
		}
	}
}
